: GW Instek GPP-4323 Four channel power supply
;
; Revision 1.3	14 Feb 2023		Changed capitalization in the idString to match firmware 1.19
; Revision 1.2	07 Nov 2020		Added series and parallel modes. Also load modes.
; Revision 1.1 	23 Apr 2020		Added #interface commands
; Revision 1.0 	20 Apr 2020		Initial release. Does not support series or parallel mode, nor Load modes.

#metadef
#idString GW Instek,GPP-4323,  
#name GWInstek GPP-4323 V1.19+

#metadef
#idString GW INSTEK,GPP-4323,  
#name GWInstek GPP-4323

#meta
#author Hexley
#idString GW Instek,GPP-4323,  
#name GWInstek GPP-4323
#handle GPP4323
#port 1026 com


; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
; NOTE: Columns ordered in the same sequence as the GPP-4323 front panel outputs: 4-1-2-3
#value CH4_V V D5 
#value CH4_I A D4 
#value CH4_W W D2
#value CH1_V V D5 
#value CH1_I A D4 
#value CH1_W W D2
#value CH2_V V D5 
#value CH2_I A D4 
#value CH2_W W D2
#value CH3_V V D5 
#value CH3_I A D4 
#value CH3_W W D2



; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; This is a single line command
#askValues :MEAS4:ALL?; [*OPC];:MEAS1:ALL?; [*OPC];:MEAS2:ALL?; [*OPC];:MEAS3:ALL?;[*OPC]; 

; Format of answer: f=float, u=remove trailing letters, x=skip
#askValuesReadFormat

; Accept this delay when reading values (seconds)
#readingDelay 5

; Mode change have a longer delay on reading values (seconds)
;#modeChangeDelay 10

; Switch meter to this mode during start, leave empty to avoid any switching
#initialMode

; String to ask about actual meter mode, 
; This is a single line command
#askMode 

; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode 

; Prepare the meter to response to #askValues
#prepareSample

; Initial commands to meter when establishing connection
#initCmd  

; Final command to meter before breaking connection
#finalCmd :LOCAL

#outputOff :ALLOUTOFF

; Strings to configure device in different modes
; First parameter must match a #value (4 parameter) and second parameter must match what #askMode returns
; First parameter is also used in shortcut menu
;#cmdMode 


#interfaceType PS PS:2 PS:3 PS:4
#interface setVoltage :VSET(channel):(value)
#interface setCurrent :ISET(channel):(value)
#interface setOn :OUTP(channel):STAT (value);
#interface getVoltage :VSET(channel)? 
#interface getCurrent :ISET(channel)?
#interface getOn :OUTP(channel):STAT? 
:readmath: listIndex(value,"OFF ON")
; The columns for the following two commands reflect the 4-1-2-3 ordering of the table
#interface readVoltage 3 6 9 0
#interface readCurrent 4 7 10 1

; ************************* Menu functions follow ***************************************
; Setup menu functions
; The parameters on the first line is: type name page 
; Settings on the following lines are:
; read: SCPI to read value from device, is used to synchronize when opening setup page or setting equal named fields. Not always used
; readformat: Parse read value.
; write: Send the value to device, this field is used in combination with data fields in the details to send updates to device.
; tip: Add this tip to all components for this input field.

; GPP-4323 front panel controls are ordered 4-1-2-3. So the tabs below are ordered in the same manner.

; *******************************************************************
; *                         CHANNEL 4                               *
; *            Volts: 0 - 15          Amps: 0 - 1                   *
; *                           Green                                 *
; *******************************************************************

#cmdSetup color - Output_4
(1,254,58)

#cmdSetup radio Voltage Output_4
:read: [*OPC];:VSET4?; 
:readformat:
:write: :VSET4: #; :OUTP4:STAT ON; [*OPC]
:update: Output
:tip: Setup this voltage, turn output 4 on
3.3V 03.300
5V 05.000
12V 12.000
15V 15.000

#cmdSetup radio Current Output_4
:read: :ISET4?; 
:readFormat:
:write: :ISET4: #
:tip: Output 4 will current limit at this current
50mA 0.0500
100mA 0.1000
;300mA 0.3000
500mA 0.5000
1A 1.0000

#cmdSetup buttonsOn Output Output_4
:read: :OUTP4:STAT?; 
:write: :OUTP4:STAT
:string: 
:tip: turn output 4 on or off
:updatealloff:
Off OFF
On ON

#cmdSetup number Voltage Output_4
:read: :VSET4? ; 
:readformat:
:write: :VSET4: #
:tip: Setup this voltage, do not turn output 4 on/off
Volt 0 15.0

#cmdSetup number Current Output_4
:read: :ISET4? ; 
:readformat:
:write: :ISET4: #
:tip: Setup this current, do not turn output 4 on/off
Amps 0.0001 1.0

#cmdSetup number OverVoltage Output_4
:read: :OUTP4:OVP?; 
:write: :OUTP4:OVP #; :OUTP4:OVP?
:tip: Set level and enable over voltage protection for Output 4
Volt 1 16.5

#cmdSetup number OverCurrent Output_4
:read: :OUTP4:OCP?
:write: :OUTP4:OCP #
:tip: Output 4 will turn off if it is above this current
Amps 0.01 1.2

#cmdSetup checkbox Protection Output_4
:read: :OUTP4:OVP:STAT?; 
:write: :OUTP4:OVP:STAT #
:string:
:tip: Output 4 overvoltage protection
:update: Status
OVP OFF ON

#cmdSetup checkbox Protection Output_4
:read: :OUTP4:OCP:STAT?; 
:write: :OUTP4:OCP:STAT #
:string:
:tip: Output 4 overcurrent protection
:update: Status
OCP OFF ON


; *******************************************************************
; *                         CHANNEL 1                               *
; *   Independent:  Volts: 0 - 32      Amps: 0 - 3                  *
; *   Series:       Volts: 0 - 64      Amps: 0 - 3                  *
; *   Parallel:		Volts: 0 - 32      Amps: 0 - 6                  *
; *                          Yellow                                 *
; *******************************************************************

#cmdSetup color - Channel_1
(255,255,16)

#cmdSetup comboboxHot Channel_Mode Channel_1
:read: :MODE1?
:write: (getElement(":LOAD1:CC OFF;[*OPC];:LOAD1:CV OFF;[*OPC];:LOAD1:CR OFF;[*OPC];:TRACK0,:LOAD1:CC OFF;[*OPC];:LOAD1:CV OFF;[*OPC];:LOAD1:CR OFF;[*OPC];:TRACK1,:LOAD1:CC OFF;[*OPC];:LOAD1:CV OFF;[*OPC];:LOAD1:CR OFF;[*OPC];:TRACK2,:LOAD1:CC ON,:LOAD1:CV ON,:LOAD1:CR ON",listIndex(value, "IND,SER,PAR,CC,CV,CR","[,]"),"[,]"))
Independent_Source IND
Series_Source_(Master) SER
Parallel_Source_(Master) PAR
CC_Load CC
CV_Load CV
CR_Load CR
:updatealloff:
:update: Channel_1.Voltage Channel_1.Current Channel_1.Output Channel_1_Mode Channel_2_Mode

#cmdSetup radio Voltage Channel_1
:read: [*OPC]; :VSET1?;
:readFormat:
:write: :VSET1: #; [*OPC]; :OUTP1:STAT ON;  [*OPC]
:update: Output
:tip: Setup this voltage, turn output 1 on
3.3V 3.300
5V 5.000
12V 12.000
15V 15.000
:enable: inList(Channel_1.Channel_Mode, "IND,SER,PAR,CV","[,]")

#cmdSetup radio Current Channel_1
:read: :ISET1?; 
:readFormat:
:write: :ISET1: #
:tip: Output 1 will current limit at this current
50mA 0.0500
500mA 0.5000
1A 1.0000
3A 3.0000
:enable: inList(Channel_1.Channel_Mode, "IND,SER,PAR,CC","[,]")

#cmdSetup buttonsOn Output Channel_1
:read: :OUTP1:STAT?; 
:write: :OUTP1:STAT 
:string: 
:tip: turn output 1 on or off
:updatealloff:
Off OFF 
On  ON

#cmdSetup number Voltage Channel_1
:read: :VSET1?; 
:readformat:
:write: :VSET1: #
:tip: Setup this voltage, do not turn output 1 on/off
Volt 0 32
:enable: inList(Channel_1.Channel_Mode, "IND,SER,PAR,CV","[,]")

#cmdSetup number Current Channel_1
:read: :ISET1?; 
:readformat:
:write: :ISET1: #
:tip: Setup this current, do not turn output 1 on/off
Amps 0.0001 3.0
:enable: inList(Channel_1.Channel_Mode, "IND,SER,PAR,CC","[,]")

#cmdSetup number Load_R Channel_1
:read: :LOAD1:RES? 
:readformat:
:write: :LOAD1:RES #
:tip: 
Ohms 1 1000
:enable: inList(Channel_1.Channel_Mode, "CR","[,]")

#cmdSetup number OverVoltage Channel_1
:read: :OUTP1:OVP?; 
:write: :OUTP1:OVP #; :OUTP1:OVP:STAT 1
:tip: Set level and enable over voltage protection for Output 1
Volt 1 35

#cmdSetup number OverCurrent Channel_1
:read: :OUTP1:OCP?; 
:write: :OUTP1:OCP #
:tip: Output 1 will turn off if it is above this current
Amps 0.01 3.5

#cmdSetup checkbox Protection Channel_1
:read: :OUTP1:OVP:STAT?; 
:write: :OUTP1:OVP:STAT #
:string:
:tip: Output 1 overvoltage protection
:update: Status
OVP OFF ON

#cmdSetup checkbox Protection Channel_1
:read: :OUTP1:OCP:STAT?; 
:write: :OUTP1:OCP:STAT #
:string:
:tip: Output 1 overcurrent protection
:update: Status
OCP OFF ON


; *******************************************************************
; *                         CHANNEL 2                               *
; *   Independent:  Volts: 0 - 32      Amps: 0 - 3                  *
; *   Series:       Slaved to Channel 1                             *
; *   Parallel:		Slaved to Channel 1                             *
; *                           Cyan                                  *
; *******************************************************************

#cmdSetup color - Channel_2
(9,255,249)

#cmdSetup comboboxHot Channel_Mode Channel_2
:read: :MODE2?
:write: (getElement(":LOAD2:CC OFF;[*OPC];:LOAD2:CV OFF;[*OPC];:LOAD2:CR OFF;[*OPC];:TRACK0,:LOAD2:CC OFF;[*OPC];:LOAD2:CV OFF;[*OPC];:LOAD2:CR OFF;[*OPC];:TRACK1,:LOAD2:CC OFF;[*OPC];:LOAD2:CV OFF;[*OPC];:LOAD2:CR OFF;[*OPC];:TRACK2,:LOAD2:CC ON,:LOAD2:CV ON,:LOAD2:CR ON",listIndex(value, "IND,SER,PAR,CC,CV,CR","[,]"),"[,]"))
Independent_Source IND
Series_Source_(Slave) SER
Parallel_Source_(Slave) PAR
CC_Load CC
CV_Load CV
CR_Load CR
:updatealloff:
;:update: Channel_1_2_Coupling Channel_1_Mode Channel_2_Mode
:update: Channel_2.Voltage Channel_2.Current Channel_2.Output Channel_1_Mode Channel_2_Mode

#cmdSetup radio Voltage Channel_2
:read: [*OPC]; :VSET2?
:readFormat:
:write: :VSET2: #; [*OPC]; :OUTP2:STAT ON; [*OPC]
:update: Output
:tip: Setup this voltage, turn output 2 on
3.3V 3.300
5V 5.000
12V 12.000
15V 15.000
:enable: inList(Channel_2.Channel_Mode, "IND,CV","[,]")

#cmdSetup radio Current Channel_2
:read: :ISET2?
:readFormat:
:write: :ISET2: #
:tip: Output 2 will current limit at this current
50mA 0.0500
500mA 0.5000
1A 1.0000
3A 3.0000
:enable: inList(Channel_2.Channel_Mode, "IND,SER,CC","[,]")

#cmdSetup buttonsOn Output Channel_2
:read: :OUTP2:STAT?
:write: :OUTP2:STAT 
:string: 
:tip: turn output 2 on or off
:updatealloff:
Off OFF
On ON

#cmdSetup number Voltage Channel_2
:read: :VSET2?
:readformat:
:write: :VSET2: #
:tip: Setup this voltage, do not turn output 2 on/off
Volt 0 32
:enable: inList(Channel_2.Channel_Mode, "IND,CV","[,]")

#cmdSetup number Current Channel_2
:read: :ISET2?
:readformat:
:write: :ISET2: #
:tip: Setup this current, do not turn output 2 on/off
Amps 0.0001 3.0
:enable: inList(Channel_2.Channel_Mode, "IND,SER,CC","[,]")

#cmdSetup number Load_R Channel_2
:read: :LOAD1:RES? 
:readformat:
:write: :LOAD1:RES #
:tip: 
Ohms 1 1000
:enable: inList(Channel_2.Channel_Mode, "CR","[,]")

#cmdSetup number OverVoltage Channel_2
:read: :OUTP2:OVP?
:write: :OUTP2:OVP #; :OUTP2:OVP:STAT 1
:tip: Set level and enable over voltage protection for Output 2
Volt 1 35

#cmdSetup number OverCurrent Channel_2
:read: :OUTP2:OCP?
:write: :OUTP2:OCP 1
:tip: Output 2 will turn off if it is above this current
Amps 0.01 3.5

#cmdSetup checkbox Protection Channel_2
:read: :OUTP2:OVP:STAT?
:write: :OUTP2:OVP:STAT #
:string:
:tip: Output 2 overvoltage protection
:update: Status
OVP OFF ON

#cmdSetup checkbox Protection Channel_2
:read: :OUTP2:OCP:STAT?
:write: :OUTP2:OCP:STAT #
:string:
:tip: Output 2 overcurrent protection
:update: Status
OCP OFF ON


; *******************************************************************
; *                         CHANNEL 3                               *
; *            Volts: 0 - 5           Amps: 0 - 1                   *
; *                         Magenta                                 *
; *******************************************************************

#cmdSetup color - Output_3
(250,141,247)

#cmdSetup radio Voltage Output_3
:read: [*OPC]; :VSET3?
:readFormat:
:write: :VSET3: #; [*OPC]; :OUTP3:STAT ON; [*OPC];
:update: Output
:tip: Setup this voltage, turn output 3 on
1.8V 1.800
3.3V 3.300
4.0V 4.000
5V 5.000

#cmdSetup radio Current Output_3
:read: :ISET3?
:readFormat:
:write: :ISET3: #
:tip: Output 3 will current limit at this current
50mA 0.0500
100mA 0.1000
500mA 0.5000
1A 1.0000

#cmdSetup buttonsOn Output Output_3
:read: :OUTP3:STAT?
:write: :OUTP3:STAT 
:tip: Turn output 3 on or off
:string: 
:updatealloff:
Off OFF 
On  ON

#cmdSetup number Voltage Output_3
:read: :VSET3?
:readformat:
:write: :VSET3: #
:tip: Setup this voltage, do not turn output 3 on/off
Volt 0 5.0

#cmdSetup number Current Output_3
:read: :ISET3?
:readformat:
:write: :ISET3: #
:tip: Setup this current, do not turn output 3 on/off
Amps 0.0001 1.0

#cmdSetup number OverVoltage Output_3
:read: :OUTP3:OVP?
:write: :OUTP3:OVP #; :OUTP3:OVP:STAT 1
:tip: Set level and enable over voltage protection for Output 3
Volt 1 5.5

#cmdSetup number OverCurrent Output_3
:read: :OUTP3:OCP?
:write: :OUTP3:OCP #
:tip: Output 3 will turn off if it is above this current
Amps 0.01 1.2

#cmdSetup checkbox Protection Output_3
:read: :OUTP3:OVP:STAT?
:write: :OUTP3:OVP:STAT #
:string:
:tip: Output 3 overvoltage protection
:update: Status
OVP OFF ON

#cmdSetup checkbox Protection Output_3
:read: :OUTP3:OCP:STAT?
:write: :OUTP3:OCP:STAT #
:string:
:tip: Output 3 overcurrent protection
:update: Status
OCP OFF ON



; *******************************************************************
; *                    COMMON CONTROLS                              *
; *******************************************************************

#cmdSetup info Channel_1_Mode
:read: :MODE1?
:readmath: getElement("Independent Source, Series Source (Master), Parallel Source (Master), CC Load, CV Load, CR Load",listIndex(value, "IND,SER,PAR,CC,CV,CR","[,]"),"[,]"))
:update: Status

#cmdSetup info Channel_2_Mode
:read: :MODE2?
:readmath: getElement("Independent Source, Series Source (Slave), Parallel Source (Slave), CC Load, CV Load, CR Load",listIndex(value, "IND,SER,PAR,CC,CV,CR","[,]"),"[,]"))
:update: Status

#cmdSetup buttons All_Outputs
:tip: Turn all outputs on or off
:update: Output
Off :ALLOUTOFF
On :ALLOUTON


